package com.alibaba.algo.cooperation.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName CaffeineConfig
 * @Description 缓存初始化
 * @Author wangke
 * @Date 2021/9/17 15:32
 */
@Configuration
public class CaffeineConfig {

    public static Cache<String, String> caffeineCache;

    @Bean
    public void init(){
        caffeineCache = Caffeine.newBuilder()
                //cache的初始容量
                .initialCapacity(5)
                //cache最大缓存数
                .maximumSize(100)
                //设置写缓存后n秒钟过期
                .expireAfterWrite(60*5, TimeUnit.SECONDS)
                .build();
    }
}
